<?php
session_start();
$username = $_POST['username'];
include_once "conn.php";
$remember = new Bbs();
$result = $remember->getInfo($username,1);  //1表示通过用户名查找
if($result['error'] == 1){ //说明出错
    $a['error'] = 1;
}
else{
    if($result['rowNum']){ //说明找到用户
        $_SESSION['loginUser'] = $username;
        $_SESSION['admin'] = $result['info']['admin'];
        $_SESSION['loginUserID'] = $result['info']['id'];
        $a['error'] = 0;
        $a['username'] = $result['info']['username'];
        $a['nickname'] = $result['info']['nickname'];
        $a['singUpDate'] = $result['info']['postDate'];
        $a['pic'] = $result['info']['pic'];
        $a['isAdmin'] = $result['info']['admin'];
        //读取当前用户最后发贴时间以及发贴数量
        $result = $remember->topic('maintopic',$_SESSION['loginUserID']);
        if($result['error'] == 0 and $result['rowCount']){
            $a['lastTitle'] = $result['info']['title'];
            $a['lastPostTime'] = $result['info']['posttime'];
            $a['total'] = $result['rowCount'];
        }
        else{
            $a['lastTitle'] = '暂未发贴';
            $a['lastPostTime'] = '暂未发贴';
            $a['total'] = '暂未发贴';
        }
        $result = $remember->topic('subtopic',$_SESSION['loginUserID']);
        if($result['error'] == 0 and $result['rowCount']){
            $a['lastReplyTime'] = $result['info']['posttime'];
        }
        else{
            $a['lastReplyTime'] = '暂未回复';
        }
    }
    else{ //说明未找到用户
        $a['error'] = 1;
    }
}
echo json_encode($a);